home *** CD-ROM | disk | FTP | other *** search
- /* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is GAds remover.
- *
- * The Initial Developer of the Original Code is
- * Ognean Dragos.
- * Portions created by the Initial Developer are Copyright (C) 2008
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
- function GadrmGeneralWrapper(){}
- GadrmGeneralWrapper.isException=false;
-
- var appEnviron=
- {
- enabled:true,
- removeAnalytics:true,
- exceptions:null,
- init:function()
- {
- var prefService = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefService);
- var br = prefService.getBranch("extensions.gadrm.");
- //br.QueryInterface(Components.interfaces.nsIPrefBranch2);
- this.enabled=br.getBoolPref("remove_enable");
- this.removeAnalytics=br.getBoolPref("remove_analytics");
- var except=gAdsRemoveUtils.getPreference("exception_list");
- if(except!="")
- {
- this.exceptions=except.split(",");
- }else
- {
- this.exceptions=null;
- }
- },
- isException:function(url)
- {
- if(this.exceptions==null)return false;
- for(var i=0;i<this.exceptions.length;i++)
- {
- var expr = this.exceptions[i];
- expr = expr.replace(/\./g, "\\.");
- expr = expr.replace(/\-/g, "\\-");
- expr = expr.replace(/\*/g, "[A-Za-z0-9_\\-\\.]*");
- //expr = expr + "$";
- var re = new RegExp(expr);
- if(re.test(url))
- return true;
- }
- return false;
- }
- }
- appEnviron.init();
- GadrmGeneralWrapper.appEnv=appEnviron;
-
- var winObserver=
- {
- tabBrowser:null,
- register:function()
- {
- this.tabBrowser=$("content");
- this.tabBrowser.addProgressListener(this);
- },
- unregister:function()
- {
- this.tabBrowser.removeProgressListener(this);
- },
- onStateChange:function(aWebProgress,aRequest,aStateFlags,aStatus)
- {
- return;
- },
- onProgressChange:function(aWebProgress,aRequest,aCurSelfProgress,aMaxSelfProgress,aCurTotalProgress,aMaxTotalProgress)
- {
- return;
- },
-
- onLocationChange:function(aWebProgress,aRequest,aLocation)
- {
- // Only watch windows that are their own parent - e.g. not frames
- if (aWebProgress.DOMWindow.parent == aWebProgress.DOMWindow)
- {
- if(!appEnviron.isException(aWebProgress.DOMWindow.location))
- {
- //requestObserver.register();
- //GadrmGeneralWrapper.gadrm.enable();
- GadrmGeneralWrapper.isException=false;
- }
- else
- {
- //GadrmGeneralWrapper.gadrm.disable();
- GadrmGeneralWrapper.isException=true;
- }
- var win=aWebProgress.DOMWindow;
- /*if(appEnviron.removeAnalytics)
- gAdsRemoveUtils.insertJsVar(win,"var urchinTracker=function(){}");*/
- }
- },
- onStatusChange:function (aWebProgress,aRequest,aStatus,aMessage)
- {
- return;
- },
- onSecurityChange:function(aWebProgress,aRequest,aState)
- {
- return;
- }
-
- }
- GadrmGeneralWrapper.winObs=winObserver;
-
- //channer observer; monitor the URL that are called from whithin the browser
- var requestObserver={
- register:function()
- {
- var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
- observerService.addObserver(this,"http-on-modify-request", false);
- },
- unregister:function()
- {
- var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
- observerService.removeObserver(this, "http-on-modify-request");
- },
- observe:function(aSubject, aTopic, aData)
- {
- if(GadrmGeneralWrapper.isException)return;
- if(aTopic=="http-on-modify-request")
- {
- try
- {
- aSubject.QueryInterface(Components.interfaces.nsIHttpChannel);
- if(gAdsRemoveUtils.isAd(aSubject.URI.asciiSpec))
- {
- //the request is dropped
- // aSubject.cancel(Components.results.NS_BINDING_ABORTED);
- aSubject.cancel(Components.results.NS_ERROR_NO_CONTENT );
- gAdsRemoveUtils.log(" --- Blocked->"+aSubject.URI.asciiSpec);
- }
- }catch(e){ gAdsRemoveUtils.log("ERROR" + e.message);}
- }
- }
- };
-
-
- //preferences observer
- var myPrefObserver =
- {
- register: function()
- {
- var prefService = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefService);
- this._branch = prefService.getBranch("extensions.gadrm.");
- this._branch.QueryInterface(Components.interfaces.nsIPrefBranch2);
- this._branch.addObserver("", this, false);
- },
-
- unregister: function()
- {
- if(!this._branch) return;
- this._branch.removeObserver("", this);
- },
-
- observe: function(aSubject, aTopic, aData)
- {
- if(aTopic != "nsPref:changed") return;
- // aSubject is the nsIPrefBranch we're observing (after appropriate QI)
- // aData is the name of the pref that's been changed (relative to aSubject)
- switch(aData)
- {
- case "remove_enable":
- GadrmGeneralWrapper.appEnv.enabled=this._branch.getBoolPref("remove_enable");
- if(GadrmGeneralWrapper.appEnv.enabled)
- {
- GadrmGeneralWrapper.gadrm.enable();
- }
- else
- {
- GadrmGeneralWrapper.gadrm.disable();
- }
- break;
- case "remove_analytics":
- GadrmGeneralWrapper.appEnv.removeAnalytics=this._branch.getBoolPref("remove_analytics");
- break;
- default:
- GadrmGeneralWrapper.appEnv.init();
- }
- }
- }
- GadrmGeneralWrapper.prefObs=myPrefObserver;
-
-
- var gadrm = {
- //init the app
-
- init: function() {
- GadrmGeneralWrapper.prefObs.register();
- if(!appEnviron.enabled)return;
- var appcontent = document.getElementById("appcontent"); // browser
- if(appcontent)
- {
- // requestObserver.register();
- //appcontent.addEventListener("DOMContentLoaded", this.onPageLoad, true);
- appcontent.addEventListener("DOMFrameContentLoaded", this.onFrameLoad, true);
- this.enable();
- }
- },
- onFrameLoad: function(aEvent) {
- if(GadrmGeneralWrapper.isException)return;
- var frame = aEvent.originalTarget;
- if(gAdsRemoveUtils.isAd(frame.src) && appEnviron.enabled)
- {
- var tmpelem=frame.contentDocument.createElement("div");
- tmpelem.style.backgroundImage="url(chrome://gadrm/content/gadrm.png)";
- tmpelem.style.backgroundPosition="left";
- tmpelem.style.backgroundAttachment="scroll";
- tmpelem.style.backgroundRepeat="no-repeat";
- tmpelem.style.padding="2px 2px 2px 32px";
- tmpelem.style.lineHeight="32px";
- tmpelem.style.height="32px";
- if(frame.parentNode)tmpelem=frame.parentNode.replaceChild(tmpelem,frame);
- /*var docRef=frame.contentDocument.getElementsByTagName("body").item(0);
- docRef.innerHTML="<strong style=\"font-size:13px;\"><img src=\"chrome://gadrm/content/gadrm.png\" align=\"absmiddle\" /> Adds blocked</strong>";*/
- }
- },
- onPageLoad: function(aEvent) {
- var doc = aEvent.originalTarget;
- },
- enable:function()
- {
- winObserver.register();
- //myPrefObserver.register();
- requestObserver.register();
- },
- disable:function()
- {
- winObserver.unregister();
- //myPrefObserver.unregister();
- requestObserver.unregister();
- }
- };
-
- GadrmGeneralWrapper.gadrm=gadrm;
-
- window.addEventListener("load", function() { gadrm.init(); }, false);
-